package com.blb.ssh.action;


import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.blb.ssh.entity.User;
import com.blb.ssh.exception.BusinessException;
import com.blb.ssh.service.UserService;

public class UserAction {
	private User user;
	private UserService userService;
	
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}


	public String index(){
		System.out.println("hello action...");
		return "index";
	}
	
	public String login(){
		HttpServletRequest request = ServletActionContext.getRequest();
		try{
			userService.login(user.getUsername(),user.getPassword());
		}catch(BusinessException e){
			e.printStackTrace();
			request.setAttribute("msg", e.getMessage());
			return "error";
		}
		return "success";
	}
	
}
